<script>
import { requestData } from './utils/http'
export default {
  globalData: {
    text: '全局数据',
    // user_id: '',
  },
  async onLaunch() {
    //   // 打开调试
    //   uni.setEnableDebug({
    //     enableDebug: true,
    //   })
    this.fnlogin()
    //https://blog.csdn.net/Technology_hands/article/details/130841631
    //https://huaweicloud.csdn.net/64edd0496ffa502025761361.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NzA4MDc1NSwiZXhwIjoxNzQyMzU3Nzc3LCJpYXQiOjE3NDE3NTI5NzcsInVzZXJuYW1lIjoicXFfNjQ0MTI0ODIifQ.HP4gEktcq5bNvyD4uZrQNlnV47m65gdpp36XgCVpP1U&spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-3-131563447-blog-118525890.235%5Ev43%5Epc_blog_bottom_relevance_base2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-3-131563447-blog-118525890.235%5Ev43%5Epc_blog_bottom_relevance_base2&utm_relevant_index=6
    this.$isResolve() //请求结束加上这个
  },

  onShow: function () {},
  methods: {
    fnlogin() {
      let user_id = uni.getStorageSync('user_id')
      if (!user_id) {
        uni.login({
          success: (res) => {
            uni.request({
              url: 'https://ya30api.hbwlife.com/wxmp/wxaccess/mp/user/login',
              method: 'POST',
              header: {},
              data: {
                wxlogin_code: res.code,
              },
              success: (ress) => {
                //console.log(ress)
                uni.removeStorageSync('access_token')
                uni.removeStorageSync('mobile')
                uni.removeStorageSync('avatarUrl')
                uni.setStorageSync('open_id', ress?.data?.datas?.open_id || '')
                uni.setStorageSync('user_id', ress?.data?.datas?.user_id || '')
                uni.setStorageSync('mobile', ress?.data?.datas.mobile || '')
                uni.setStorageSync(
                  'avatarUrl',
                  ress?.data?.datas.avatarUrl || ''
                )
                uni.setStorageSync(
                  'access_token',
                  ress?.data?.datas?.access_token || ''
                )
              },
              complete: () => {},
              fail: (err) => {
                reject(err)
              },
            })
          },
        })
      }
    },
  },
  onHide: function () {},
}
</script>
<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import '@/uni_modules/uview-ui/index.scss';

page {
  font-size: 32rpx !important;
}

uni-toast .uni-toast__content {
  font-size: 28rpx;
  white-space: pre-wrap;
}
</style>
.
